! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! Auxiliary Routines File
! 
! Generated by KPP-2.2.4_gc symbolic chemistry Kinetics PreProcessor
!       (http://www.cs.vt.edu/~asandu/Software/KPP)
! KPP is distributed under GPL, the general public licence
!       (http://www.gnu.org/copyleft/gpl.html)
! (C) 1995-1997, V. Damian & A. Sandu, CGRER, Univ. Iowa
! (C) 1997-2005, A. Sandu, Michigan Tech, Virginia Tech
!     With important contributions from:
!        M. Damian, Villanova University, USA
!        R. Sander, Max-Planck Institute for Chemistry, Mainz, Germany
! 
! File                 : gckpp_Util.f90
! Time                 : Sat Oct 24 17:55:27 2020
! Working directory    : /n/home08/kbates/GC/Code.12.3.0_racm2/KPP/Tropchem
! Equation file        : gckpp.kpp
! Output root filename : gckpp
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



MODULE gckpp_Util

  USE gckpp_Parameters
  IMPLICIT NONE

CONTAINS



! User INLINED Utility Functions

! End INLINED Utility Functions

! Utility Functions from KPP_HOME/util/util
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! UTIL - Utility functions
!   Arguments :
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

! ****************************************************************
!                            
! InitSaveData - Opens the data file for writing
!   Parameters :                                                  
!
! ****************************************************************

      SUBROUTINE InitSaveData ()

      USE gckpp_Parameters

      open(10, file='gckpp.dat')

      END SUBROUTINE InitSaveData

! End of InitSaveData function
! ****************************************************************

! ****************************************************************
!                            
! SaveData - Write LOOKAT species in the data file 
!   Parameters :                                                  
!
! ****************************************************************

      SUBROUTINE SaveData ()

      USE gckpp_Global
      USE gckpp_Monitor

      INTEGER i

      WRITE(10,999) (TIME-TSTART)/3600.D0,  &
                   (C(LOOKAT(i))/CFACTOR, i=1,NLOOKAT)
999   FORMAT(E24.16,100(1X,E24.16))

      END SUBROUTINE SaveData

! End of SaveData function
! ****************************************************************

! ****************************************************************
!                            
! CloseSaveData - Close the data file 
!   Parameters :                                                  
!
! ****************************************************************

      SUBROUTINE CloseSaveData ()

      USE gckpp_Parameters

      CLOSE(10)

      END SUBROUTINE CloseSaveData

! End of CloseSaveData function
! ****************************************************************

! ****************************************************************
!                            
! GenerateMatlab - Generates MATLAB file to load the data file 
!   Parameters : 
!                It will have a character string to prefix each 
!                species name with.                                                 
!
! ****************************************************************

      SUBROUTINE GenerateMatlab ( PREFIX )

      USE gckpp_Parameters
      USE gckpp_Global
      USE gckpp_Monitor

      
      CHARACTER(LEN=8) PREFIX 
      INTEGER i

      open(20, file='gckpp.m')
      write(20,*) 'load gckpp.dat;'
      write(20,990) PREFIX
990   FORMAT(A1,'c = gckpp;')
      write(20,*) 'clear gckpp;'
      write(20,991) PREFIX, PREFIX
991   FORMAT(A1,'t=',A1,'c(:,1);')
      write(20,992) PREFIX
992   FORMAT(A1,'c(:,1)=[];')

      do i=1,NLOOKAT
        write(20,993) PREFIX, SPC_NAMES(LOOKAT(i)), PREFIX, i
993     FORMAT(A1,A6,' = ',A1,'c(:,',I2,');')
      end do
      
      CLOSE(20)

      END SUBROUTINE GenerateMatlab

! End of GenerateMatlab function
! ****************************************************************


! End Utility Functions from KPP_HOME/util/util
! End of UTIL function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! Shuffle_user2kpp - function to copy concentrations from USER to KPP
!   Arguments :
!      V_USER    - Concentration of variable species in USER's order
!      V         - Concentrations of variable species (local)
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SUBROUTINE Shuffle_user2kpp ( V_USER, V )

! V_USER - Concentration of variable species in USER's order
  REAL(kind=dp) :: V_USER(NVAR)
! V - Concentrations of variable species (local)
  REAL(kind=dp) :: V(NVAR)

  V(222) = V_USER(1)
  V(264) = V_USER(2)
  V(250) = V_USER(3)
  V(4) = V_USER(4)
  V(278) = V_USER(5)
  V(145) = V_USER(6)
  V(231) = V_USER(7)
  V(148) = V_USER(8)
  V(235) = V_USER(9)
  V(104) = V_USER(10)
  V(292) = V_USER(11)
  V(158) = V_USER(12)
  V(149) = V_USER(13)
  V(244) = V_USER(14)
  V(233) = V_USER(15)
  V(98) = V_USER(16)
  V(181) = V_USER(17)
  V(171) = V_USER(18)
  V(172) = V_USER(19)
  V(120) = V_USER(20)
  V(176) = V_USER(21)
  V(153) = V_USER(22)
  V(89) = V_USER(23)
  V(121) = V_USER(24)
  V(1) = V_USER(25)
  V(2) = V_USER(26)
  V(3) = V_USER(27)
  V(275) = V_USER(28)
  V(251) = V_USER(29)
  V(99) = V_USER(30)
  V(191) = V_USER(31)
  V(127) = V_USER(32)
  V(92) = V_USER(33)
  V(90) = V_USER(34)
  V(122) = V_USER(35)
  V(287) = V_USER(36)
  V(159) = V_USER(37)
  V(123) = V_USER(38)
  V(128) = V_USER(39)
  V(241) = V_USER(40)
  V(274) = V_USER(41)
  V(135) = V_USER(42)
  V(280) = V_USER(43)
  V(5) = V_USER(44)
  V(93) = V_USER(45)
  V(94) = V_USER(46)
  V(165) = V_USER(47)
  V(154) = V_USER(48)
  V(184) = V_USER(49)
  V(130) = V_USER(50)
  V(173) = V_USER(51)
  V(174) = V_USER(52)
  V(267) = V_USER(53)
  V(131) = V_USER(54)
  V(193) = V_USER(55)
  V(258) = V_USER(56)
  V(232) = V_USER(57)
  V(207) = V_USER(58)
  V(269) = V_USER(59)
  V(255) = V_USER(60)
  V(161) = V_USER(61)
  V(263) = V_USER(62)
  V(257) = V_USER(63)
  V(273) = V_USER(64)
  V(208) = V_USER(65)
  V(109) = V_USER(66)
  V(132) = V_USER(67)
  V(243) = V_USER(68)
  V(133) = V_USER(69)
  V(281) = V_USER(70)
  V(214) = V_USER(71)
  V(215) = V_USER(72)
  V(150) = V_USER(73)
  V(166) = V_USER(74)
  V(151) = V_USER(75)
  V(162) = V_USER(76)
  V(240) = V_USER(77)
  V(194) = V_USER(78)
  V(95) = V_USER(79)
  V(100) = V_USER(80)
  V(80) = V_USER(81)
  V(163) = V_USER(82)
  V(106) = V_USER(83)
  V(118) = V_USER(84)
  V(112) = V_USER(85)
  V(113) = V_USER(86)
  V(107) = V_USER(87)
  V(220) = V_USER(88)
  V(24) = V_USER(89)
  V(119) = V_USER(90)
  V(6) = V_USER(91)
  V(268) = V_USER(92)
  V(197) = V_USER(93)
  V(105) = V_USER(94)
  V(242) = V_USER(95)
  V(129) = V_USER(96)
  V(183) = V_USER(97)
  V(114) = V_USER(98)
  V(188) = V_USER(99)
  V(7) = V_USER(100)
  V(8) = V_USER(101)
  V(262) = V_USER(102)
  V(9) = V_USER(103)
  V(10) = V_USER(104)
  V(223) = V_USER(105)
  V(190) = V_USER(106)
  V(177) = V_USER(107)
  V(170) = V_USER(108)
  V(227) = V_USER(109)
  V(204) = V_USER(110)
  V(218) = V_USER(111)
  V(254) = V_USER(112)
  V(245) = V_USER(113)
  V(256) = V_USER(114)
  V(189) = V_USER(117)
  V(248) = V_USER(118)
  V(11) = V_USER(119)
  V(12) = V_USER(120)
  V(14) = V_USER(123)
  V(13) = V_USER(124)
  V(271) = V_USER(127)
  V(236) = V_USER(128)
  V(198) = V_USER(129)
  V(221) = V_USER(130)
  V(225) = V_USER(131)
  V(175) = V_USER(132)
  V(237) = V_USER(133)
  V(115) = V_USER(134)
  V(282) = V_USER(137)
  V(290) = V_USER(138)
  V(202) = V_USER(139)
  V(261) = V_USER(140)
  V(196) = V_USER(141)
  V(164) = V_USER(142)
  V(187) = V_USER(143)
  V(289) = V_USER(144)
  V(91) = V_USER(145)
  V(203) = V_USER(146)
  V(217) = V_USER(147)
  V(160) = V_USER(148)
  V(117) = V_USER(149)
  V(266) = V_USER(150)
  V(157) = V_USER(151)
  V(15) = V_USER(152)
  V(182) = V_USER(153)
  V(179) = V_USER(154)
  V(276) = V_USER(155)
  V(219) = V_USER(156)
  V(186) = V_USER(157)
  V(152) = V_USER(158)
  V(260) = V_USER(159)
  V(288) = V_USER(160)
  V(286) = V_USER(161)
  V(285) = V_USER(162)
  V(180) = V_USER(163)
  V(284) = V_USER(165)
  V(136) = V_USER(166)
  V(283) = V_USER(167)
  V(124) = V_USER(168)
  V(246) = V_USER(169)
  V(247) = V_USER(170)
  V(16) = V_USER(171)
  V(137) = V_USER(172)
  V(253) = V_USER(173)
  V(146) = V_USER(174)
  V(96) = V_USER(175)
  V(228) = V_USER(177)
  V(141) = V_USER(178)
  V(97) = V_USER(179)
  V(216) = V_USER(180)
  V(270) = V_USER(181)
  V(142) = V_USER(182)
  V(224) = V_USER(183)
  V(17) = V_USER(184)
  V(249) = V_USER(185)
  V(291) = V_USER(186)
  V(272) = V_USER(187)
  V(213) = V_USER(188)
  V(125) = V_USER(189)
  V(126) = V_USER(190)
  V(279) = V_USER(191)
  V(252) = V_USER(192)
  V(265) = V_USER(193)
  V(167) = V_USER(194)
  V(155) = V_USER(195)
  V(168) = V_USER(196)
  V(199) = V_USER(197)
  V(138) = V_USER(198)
  V(277) = V_USER(199)
  V(18) = V_USER(200)
  V(19) = V_USER(201)
  V(20) = V_USER(202)
  V(21) = V_USER(203)
  V(22) = V_USER(204)
  V(23) = V_USER(205)
  V(25) = V_USER(206)
  V(101) = V_USER(207)
  V(259) = V_USER(209)
  V(156) = V_USER(210)
  V(102) = V_USER(211)
  V(103) = V_USER(212)
  V(192) = V_USER(213)
  V(134) = V_USER(214)
  V(116) = V_USER(215)
  V(147) = V_USER(216)
  V(26) = V_USER(217)
  V(27) = V_USER(218)
  V(81) = V_USER(219)
  V(82) = V_USER(220)
  V(83) = V_USER(221)
  V(84) = V_USER(222)
  V(85) = V_USER(223)
  V(86) = V_USER(224)
  V(87) = V_USER(225)
  V(88) = V_USER(226)
  V(206) = V_USER(227)
  V(234) = V_USER(228)
  V(195) = V_USER(229)
  V(210) = V_USER(230)
  V(185) = V_USER(231)
  V(178) = V_USER(232)
  V(108) = V_USER(233)
  V(143) = V_USER(234)
  V(239) = V_USER(235)
  V(209) = V_USER(236)
  V(205) = V_USER(237)
  V(139) = V_USER(238)
  V(140) = V_USER(239)
  V(200) = V_USER(240)
  V(110) = V_USER(241)
  V(226) = V_USER(242)
  V(229) = V_USER(243)
  V(230) = V_USER(244)
  V(144) = V_USER(245)
  V(111) = V_USER(247)
  V(201) = V_USER(248)
  V(211) = V_USER(249)
  V(212) = V_USER(252)
  V(169) = V_USER(253)
  V(238) = V_USER(254)
  V(28) = V_USER(257)
  V(29) = V_USER(258)
  V(30) = V_USER(259)
  V(31) = V_USER(260)
  V(32) = V_USER(261)
  V(33) = V_USER(262)
  V(34) = V_USER(263)
  V(35) = V_USER(264)
  V(36) = V_USER(265)
  V(37) = V_USER(266)
  V(38) = V_USER(267)
  V(39) = V_USER(268)
  V(40) = V_USER(269)
  V(41) = V_USER(270)
  V(42) = V_USER(271)
  V(43) = V_USER(272)
  V(44) = V_USER(273)
  V(45) = V_USER(274)
  V(46) = V_USER(275)
  V(47) = V_USER(276)
  V(48) = V_USER(277)
  V(49) = V_USER(278)
  V(50) = V_USER(279)
  V(51) = V_USER(280)
  V(52) = V_USER(281)
  V(53) = V_USER(282)
  V(54) = V_USER(283)
  V(55) = V_USER(284)
  V(56) = V_USER(285)
      
END SUBROUTINE Shuffle_user2kpp

! End of Shuffle_user2kpp function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! Shuffle_kpp2user - function to restore concentrations from KPP to USER
!   Arguments :
!      V         - Concentrations of variable species (local)
!      V_USER    - Concentration of variable species in USER's order
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SUBROUTINE Shuffle_kpp2user ( V, V_USER )

! V - Concentrations of variable species (local)
  REAL(kind=dp) :: V(NVAR)
! V_USER - Concentration of variable species in USER's order
  REAL(kind=dp) :: V_USER(NVAR)

  V_USER(1) = V(222)
  V_USER(2) = V(264)
  V_USER(3) = V(250)
  V_USER(4) = V(4)
  V_USER(5) = V(278)
  V_USER(6) = V(145)
  V_USER(7) = V(231)
  V_USER(8) = V(148)
  V_USER(9) = V(235)
  V_USER(10) = V(104)
  V_USER(11) = V(292)
  V_USER(12) = V(158)
  V_USER(13) = V(149)
  V_USER(14) = V(244)
  V_USER(15) = V(233)
  V_USER(16) = V(98)
  V_USER(17) = V(181)
  V_USER(18) = V(171)
  V_USER(19) = V(172)
  V_USER(20) = V(120)
  V_USER(21) = V(176)
  V_USER(22) = V(153)
  V_USER(23) = V(89)
  V_USER(24) = V(121)
  V_USER(25) = V(1)
  V_USER(26) = V(2)
  V_USER(27) = V(3)
  V_USER(28) = V(275)
  V_USER(29) = V(251)
  V_USER(30) = V(99)
  V_USER(31) = V(191)
  V_USER(32) = V(127)
  V_USER(33) = V(92)
  V_USER(34) = V(90)
  V_USER(35) = V(122)
  V_USER(36) = V(287)
  V_USER(37) = V(159)
  V_USER(38) = V(123)
  V_USER(39) = V(128)
  V_USER(40) = V(241)
  V_USER(41) = V(274)
  V_USER(42) = V(135)
  V_USER(43) = V(280)
  V_USER(44) = V(5)
  V_USER(45) = V(93)
  V_USER(46) = V(94)
  V_USER(47) = V(165)
  V_USER(48) = V(154)
  V_USER(49) = V(184)
  V_USER(50) = V(130)
  V_USER(51) = V(173)
  V_USER(52) = V(174)
  V_USER(53) = V(267)
  V_USER(54) = V(131)
  V_USER(55) = V(193)
  V_USER(56) = V(258)
  V_USER(57) = V(232)
  V_USER(58) = V(207)
  V_USER(59) = V(269)
  V_USER(60) = V(255)
  V_USER(61) = V(161)
  V_USER(62) = V(263)
  V_USER(63) = V(257)
  V_USER(64) = V(273)
  V_USER(65) = V(208)
  V_USER(66) = V(109)
  V_USER(67) = V(132)
  V_USER(68) = V(243)
  V_USER(69) = V(133)
  V_USER(70) = V(281)
  V_USER(71) = V(214)
  V_USER(72) = V(215)
  V_USER(73) = V(150)
  V_USER(74) = V(166)
  V_USER(75) = V(151)
  V_USER(76) = V(162)
  V_USER(77) = V(240)
  V_USER(78) = V(194)
  V_USER(79) = V(95)
  V_USER(80) = V(100)
  V_USER(81) = V(80)
  V_USER(82) = V(163)
  V_USER(83) = V(106)
  V_USER(84) = V(118)
  V_USER(85) = V(112)
  V_USER(86) = V(113)
  V_USER(87) = V(107)
  V_USER(88) = V(220)
  V_USER(89) = V(24)
  V_USER(90) = V(119)
  V_USER(91) = V(6)
  V_USER(92) = V(268)
  V_USER(93) = V(197)
  V_USER(94) = V(105)
  V_USER(95) = V(242)
  V_USER(96) = V(129)
  V_USER(97) = V(183)
  V_USER(98) = V(114)
  V_USER(99) = V(188)
  V_USER(100) = V(7)
  V_USER(101) = V(8)
  V_USER(102) = V(262)
  V_USER(103) = V(9)
  V_USER(104) = V(10)
  V_USER(105) = V(223)
  V_USER(106) = V(190)
  V_USER(107) = V(177)
  V_USER(108) = V(170)
  V_USER(109) = V(227)
  V_USER(110) = V(204)
  V_USER(111) = V(218)
  V_USER(112) = V(254)
  V_USER(113) = V(245)
  V_USER(114) = V(256)
  V_USER(117) = V(189)
  V_USER(118) = V(248)
  V_USER(119) = V(11)
  V_USER(120) = V(12)
  V_USER(123) = V(14)
  V_USER(124) = V(13)
  V_USER(127) = V(271)
  V_USER(128) = V(236)
  V_USER(129) = V(198)
  V_USER(130) = V(221)
  V_USER(131) = V(225)
  V_USER(132) = V(175)
  V_USER(133) = V(237)
  V_USER(134) = V(115)
  V_USER(137) = V(282)
  V_USER(138) = V(290)
  V_USER(139) = V(202)
  V_USER(140) = V(261)
  V_USER(141) = V(196)
  V_USER(142) = V(164)
  V_USER(143) = V(187)
  V_USER(144) = V(289)
  V_USER(145) = V(91)
  V_USER(146) = V(203)
  V_USER(147) = V(217)
  V_USER(148) = V(160)
  V_USER(149) = V(117)
  V_USER(150) = V(266)
  V_USER(151) = V(157)
  V_USER(152) = V(15)
  V_USER(153) = V(182)
  V_USER(154) = V(179)
  V_USER(155) = V(276)
  V_USER(156) = V(219)
  V_USER(157) = V(186)
  V_USER(158) = V(152)
  V_USER(159) = V(260)
  V_USER(160) = V(288)
  V_USER(161) = V(286)
  V_USER(162) = V(285)
  V_USER(163) = V(180)
  V_USER(165) = V(284)
  V_USER(166) = V(136)
  V_USER(167) = V(283)
  V_USER(168) = V(124)
  V_USER(169) = V(246)
  V_USER(170) = V(247)
  V_USER(171) = V(16)
  V_USER(172) = V(137)
  V_USER(173) = V(253)
  V_USER(174) = V(146)
  V_USER(175) = V(96)
  V_USER(177) = V(228)
  V_USER(178) = V(141)
  V_USER(179) = V(97)
  V_USER(180) = V(216)
  V_USER(181) = V(270)
  V_USER(182) = V(142)
  V_USER(183) = V(224)
  V_USER(184) = V(17)
  V_USER(185) = V(249)
  V_USER(186) = V(291)
  V_USER(187) = V(272)
  V_USER(188) = V(213)
  V_USER(189) = V(125)
  V_USER(190) = V(126)
  V_USER(191) = V(279)
  V_USER(192) = V(252)
  V_USER(193) = V(265)
  V_USER(194) = V(167)
  V_USER(195) = V(155)
  V_USER(196) = V(168)
  V_USER(197) = V(199)
  V_USER(198) = V(138)
  V_USER(199) = V(277)
  V_USER(200) = V(18)
  V_USER(201) = V(19)
  V_USER(202) = V(20)
  V_USER(203) = V(21)
  V_USER(204) = V(22)
  V_USER(205) = V(23)
  V_USER(206) = V(25)
  V_USER(207) = V(101)
  V_USER(209) = V(259)
  V_USER(210) = V(156)
  V_USER(211) = V(102)
  V_USER(212) = V(103)
  V_USER(213) = V(192)
  V_USER(214) = V(134)
  V_USER(215) = V(116)
  V_USER(216) = V(147)
  V_USER(217) = V(26)
  V_USER(218) = V(27)
  V_USER(219) = V(81)
  V_USER(220) = V(82)
  V_USER(221) = V(83)
  V_USER(222) = V(84)
  V_USER(223) = V(85)
  V_USER(224) = V(86)
  V_USER(225) = V(87)
  V_USER(226) = V(88)
  V_USER(227) = V(206)
  V_USER(228) = V(234)
  V_USER(229) = V(195)
  V_USER(230) = V(210)
  V_USER(231) = V(185)
  V_USER(232) = V(178)
  V_USER(233) = V(108)
  V_USER(234) = V(143)
  V_USER(235) = V(239)
  V_USER(236) = V(209)
  V_USER(237) = V(205)
  V_USER(238) = V(139)
  V_USER(239) = V(140)
  V_USER(240) = V(200)
  V_USER(241) = V(110)
  V_USER(242) = V(226)
  V_USER(243) = V(229)
  V_USER(244) = V(230)
  V_USER(245) = V(144)
  V_USER(247) = V(111)
  V_USER(248) = V(201)
  V_USER(249) = V(211)
  V_USER(252) = V(212)
  V_USER(253) = V(169)
  V_USER(254) = V(238)
  V_USER(257) = V(28)
  V_USER(258) = V(29)
  V_USER(259) = V(30)
  V_USER(260) = V(31)
  V_USER(261) = V(32)
  V_USER(262) = V(33)
  V_USER(263) = V(34)
  V_USER(264) = V(35)
  V_USER(265) = V(36)
  V_USER(266) = V(37)
  V_USER(267) = V(38)
  V_USER(268) = V(39)
  V_USER(269) = V(40)
  V_USER(270) = V(41)
  V_USER(271) = V(42)
  V_USER(272) = V(43)
  V_USER(273) = V(44)
  V_USER(274) = V(45)
  V_USER(275) = V(46)
  V_USER(276) = V(47)
  V_USER(277) = V(48)
  V_USER(278) = V(49)
  V_USER(279) = V(50)
  V_USER(280) = V(51)
  V_USER(281) = V(52)
  V_USER(282) = V(53)
  V_USER(283) = V(54)
  V_USER(284) = V(55)
  V_USER(285) = V(56)
      
END SUBROUTINE Shuffle_kpp2user

! End of Shuffle_kpp2user function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! GetMass - compute total mass of selected atoms
!   Arguments :
!      CL        - Concentration of all species (local)
!      Mass      - value of mass balance
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SUBROUTINE GetMass ( CL, Mass )

! CL - Concentration of all species (local)
  REAL(kind=dp) :: CL(NSPEC)
! Mass - value of mass balance
  REAL(kind=dp) :: Mass(1)

      
END SUBROUTINE GetMass

! End of GetMass function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! ComputeFamilies - function to calculate user-defined Prod/Loss families
!   Arguments :
!      V         - Concentrations of variable species (local)
!      FAM       - Accumulated user-defined prod/loss families.
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SUBROUTINE ComputeFamilies ( V, FAM )

! V - Concentrations of variable species (local)
  REAL(kind=dp) :: V(NVAR)
! FAM - Accumulated user-defined prod/loss families.
  REAL(kind=dp) :: FAM(NFAM)


! Computation of prod/loss families
  FAM(1) = V(28)+V(28)+V(38)+V(28)+V(28)+V(28)+V(58)+V(40)+V(58)+V(58)+V(56)+V(58)+V(38)+V(58)+V(38)+V(53)+V(53)+V(53)&
             &+V(28)+V(38)+0.96*V(30)+0.21*V(57)+1.78*V(52)+0.36*V(52)+V(58)+V(28)+V(38)+0.15*V(41)+0.15*V(57)+0.15*V(38)&
             &+0.81*V(38)+V(53)+V(28)+V(51)+V(28)+V(28)+V(28)+V(28)+V(28)+2*V(28)+V(38)+V(58)+V(28)+V(53)+V(51)+1.394*V(39)&
             &+V(38)+1.58*V(38)+1.01*V(38)+V(53)+1.15*V(53)+0.15*V(53)+V(28)+V(53)+V(51)+V(40)+V(51)+V(38)+V(38)+V(28)+V(28)&
             &+V(28)+V(28)+V(53)+V(53)+V(53)+V(53)+V(58)+V(58)+V(28)+V(28)+0.82*V(40)+0.78*V(40)+V(28)+2*V(40)+0.5*V(40)&
             &+V(57)+0.5*V(40)+V(40)+V(51)+V(51)+2*V(28)+V(53)+V(53)+V(28)+0.3*V(28)+V(38)+0.4*V(38)+V(28)+V(40)+V(28)+0.995&
             &*V(28)+V(28)+V(45)+0.95*V(68)+0.95*V(54)+V(45)+0.95*V(68)+0.95*V(69)+V(28)+V(28)+2*V(55)+0.7*V(55)+0.7*V(55)&
             &+0.918*V(69)+V(55)+V(28)+V(28)
  FAM(2) = V(29)+V(29)+V(29)+V(29)+V(29)+2*V(29)+V(29)+V(29)+V(29)+1.4*V(29)+1.04*V(29)+1.04*V(29)+0.0599999*V(29)+0.04&
             &*V(29)+V(29)+0.106*V(29)+0.04*V(29)+0.34*V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)&
             &+V(29)+V(29)+1.5*V(29)+V(29)+V(29)+2*V(29)+0.64*V(29)+V(29)+V(29)+2*V(29)+2*V(29)+V(29)+V(29)+V(29)+V(29)&
             &+V(29)+V(29)+2*V(29)+2*V(29)+2*V(29)+2*V(29)+2*V(29)+2*V(29)+2*V(29)+0.9*V(29)+0.9*V(29)+0.388*V(29)+V(29)&
             &+V(29)+V(29)+V(29)+V(29)+2*V(29)+2*V(29)+V(29)+2*V(29)+V(29)+V(29)+V(29)+2*V(29)+2*V(29)+0.5*V(29)+V(29)+V(29)&
             &+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+2&
             &*V(29)+2*V(29)+2*V(29)+3*V(29)+3*V(29)+3*V(29)+4*V(29)+4*V(29)+4*V(29)+V(29)+V(29)+2*V(29)+2*V(29)+V(29)+V(29)&
             &+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+2*V(29)+V(29)+2*V(29)+V(29)+V(29)+2*V(29)+V(29)+V(29)+V(29)&
             &+V(29)+1.5*V(60)+1.5*V(59)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(29)+V(65)+V(29)+V(29)+V(29)+V(61)+V(29)&
             &+V(29)+V(29)
  FAM(3) = V(30)+V(51)+0.05*V(38)+0.728*V(53)+V(30)+0.5*V(53)+V(30)+V(30)+0.5*V(38)+0.075*V(53)+0.29*V(38)+0.33*V(53)&
             &+0.595*V(53)+0.375*V(56)+0.39*V(38)+0.56*V(58)+V(30)+0.03*V(38)+0.505*V(52)+V(39)+2*V(30)+V(30)+2*V(51)+V(51)&
             &+0.5*V(41)+0.495*V(38)+0.56*V(58)+0.625*V(53)+0.5*V(51)+0.6*V(53)+0.678*V(53)+0.89*V(53)+0.09*V(53)+0.857&
             &*V(53)+0.5*V(53)+0.21*V(51)+V(30)+V(30)+V(30)+V(30)+V(30)+0.09*V(53)+1.5*V(30)+0.14*V(40)+0.14*V(40)+0.14&
             &*V(57)+0.5*V(53)+0.55*V(53)+V(57)+V(30)+V(30)+0.88*V(30)+V(30)+V(30)+V(30)+V(38)+2*V(30)+2*V(30)+V(38)+V(30)&
             &+V(30)+V(38)+V(38)+0.67*V(53)+0.5*V(38)+0.5*V(53)+V(38)+V(38)+1.89*V(53)+0.364*V(52)+0.33*V(55)+0.11*V(55)&
             &+V(40)+1.5*V(52)+V(53)+V(53)+V(30)
  FAM(4) = V(31)+V(31)+V(31)+V(31)+V(31)+V(31)+V(31)+V(31)
  FAM(5) = V(32)+V(38)+V(32)+V(32)+V(53)+V(53)+V(58)+V(32)
  FAM(6) = V(33)+V(33)
  FAM(7) = V(34)+V(34)+V(38)+V(34)+V(34)+V(53)+V(53)+V(58)+V(34)+0.02*V(40)+0.02*V(40)+0.02*V(57)
  FAM(8) = V(35)
  FAM(9) = V(36)
  FAM(10) = V(37)
  FAM(11) = V(38)+V(38)+V(38)+2*V(38)+V(38)+V(38)+0.05*V(38)+V(58)+0.57*V(58)+V(38)+0.82*V(38)+0.35*V(53)+0.122*V(53)&
              &+0.5*V(53)+0.07*V(38)+0.07*V(38)+0.75*V(52)+0.75*V(52)+0.75*V(52)+0.07*V(38)+V(58)+0.5*V(38)+0.75*V(40)+1.25&
              &*V(58)+0.15*V(38)+0.063*V(38)+0.102*V(53)+0.075*V(53)+0.75*V(58)+0.75*V(58)+0.95*V(58)+0.5*V(53)+0.75*V(58)&
              &+1.22*V(38)+0.75*V(38)+0.95*V(53)+0.89*V(53)+1.255*V(53)+0.625*V(56)+0.75*V(38)+0.785*V(38)+1.25*V(58)+0.59&
              &*V(38)+0.5*V(58)+0.19*V(38)+V(38)+0.732*V(52)+V(58)+0.456*V(38)+0.6*V(58)+0.12*V(53)+V(38)+2*V(38)+V(57)&
              &+V(57)+0.375*V(53)+0.375*V(53)+V(38)+0.445*V(53)+V(38)+V(41)+V(38)+0.747*V(38)+0.4*V(53)+0.143*V(53)+0.39&
              &*V(58)+0.5*V(53)+0.07*V(38)+V(58)+V(38)+0.62*V(51)+0.2*V(52)+V(38)+V(51)+V(38)+V(38)+V(38)+0.15*V(39)+0.07&
              &*V(38)+0.7*V(38)+0.44*V(38)+0.35*V(53)+0.08*V(53)+0.08*V(53)+V(38)+V(38)+V(38)+V(38)+V(38)+V(38)+0.23*V(40)&
              &+0.75*V(40)+0.04*V(57)+0.231*V(40)+1.04*V(38)+0.385*V(57)+0.385*V(38)+0.287*V(40)+V(38)+0.965*V(40)+0.287&
              &*V(57)+0.287*V(40)+0.202*V(40)+0.504*V(40)+V(53)+0.55*V(53)+V(38)+0.9*V(38)+V(38)+V(38)+V(38)+V(38)+V(58)&
              &+0.71*V(38)+0.71*V(38)+0.71*V(38)+0.3*V(53)+0.5*V(38)+V(38)+0.5*V(53)+V(38)+V(38)+V(38)+0.4*V(38)+V(38)+V(53)&
              &+V(38)+0.8*V(38)+2*V(38)+V(55)+V(69)+V(68)+V(45)+V(53)+V(45)+V(68)+V(69)+V(38)+V(38)+V(55)+V(38)+V(38)
  FAM(12) = 0.134*V(52)+V(39)+0.5*V(41)+0.278*V(53)+0.142*V(53)+0.16*V(51)+0.057*V(39)+0.65*V(53)+0.07*V(53)+0.07*V(53)&
              &+V(39)+0.07*V(40)+0.01*V(57)+0.364*V(52)
  FAM(13) = V(40)+0.14*V(58)+0.57*V(58)+0.75*V(40)+0.09*V(58)+0.033*V(53)+0.07*V(58)+0.54*V(58)+0.25*V(58)+V(40)+V(40)&
              &+V(41)+0.35*V(41)+0.64*V(40)+0.791*V(40)+0.13*V(58)+0.09*V(53)+0.57*V(58)+V(41)+V(41)+V(41)+V(41)+0.09*V(53)&
              &+V(40)+0.5*V(55)+0.43*V(40)+0.75*V(40)+V(57)+V(40)+0.65*V(40)+0.65*V(40)+0.491*V(40)+0.08*V(40)+1.24*V(40)&
              &+0.93*V(40)+1.24*V(57)+1.24*V(40)+0.64*V(40)+1.21*V(40)+V(40)+V(40)+V(40)+V(40)+V(40)+0.13*V(58)+V(40)+V(40)&
              &+V(40)+V(40)
  FAM(14) = 0.15*V(41)+0.5*V(41)+V(41)+V(41)+V(41)+V(41)+V(41)+V(53)+V(41)+V(41)+V(41)+V(41)+V(41)+V(41)+V(41)+V(41)&
              &+V(41)+V(41)+V(58)+0.08*V(53)+0.08*V(53)+V(41)
  FAM(15) = 0.05*V(42)+0.01*V(68)+0.01*V(68)+0.05*V(42)+0.01*V(68)+0.01*V(68)+V(42)
  FAM(16) = 0.53*V(44)
  FAM(17) = 0.118*V(44)+0.28*V(68)+0.84*V(68)
  FAM(18) = V(45)+0.5*V(54)+V(45)+V(45)+V(45)+V(45)+V(45)+V(45)+V(45)
  FAM(19) = 0.1*V(46)
  FAM(20) = 0.28*V(68)+0.49*V(68)+0.95*V(68)+0.5*V(54)+0.224*V(68)+0.49*V(68)+0.95*V(68)+2*V(69)+0.918*V(69)+0.918*V(69)&
              &+V(68)+V(53)+V(68)+2.05*V(69)+0.918*V(69)+V(68)+V(53)+2.05*V(69)+V(68)+V(69)+V(68)+V(53)+V(68)+3.05*V(69)
  FAM(21) = 0.73*V(48)+0.73*V(48)
  FAM(22) = 0.1*V(49)
  FAM(23) = 0.1*V(50)
  FAM(24) = V(51)+V(51)+V(51)+0.6*V(51)+V(51)+V(51)+V(51)+V(51)+V(51)+0.5*V(51)+V(51)+V(51)+0.41*V(51)+0.3*V(52)+V(51)&
              &+V(51)+V(51)+V(51)+V(51)+V(51)+0.5*V(51)+V(51)+2*V(51)+V(51)+V(51)+V(51)+V(51)+V(51)+V(51)+V(51)+V(51)+V(51)&
              &+V(51)+0.5*V(51)+0.5*V(51)+V(51)+0.5*V(52)
  FAM(25) = V(52)+0.94*V(52)+0.7*V(52)+0.7*V(52)+0.919*V(52)+0.7*V(52)+0.134*V(52)+0.085*V(53)+0.088*V(53)+0.216*V(53)&
              &+0.06*V(52)+0.216*V(53)+0.48*V(53)+0.072*V(55)+0.085*V(53)+V(53)+V(53)+V(53)+0.25*V(53)+0.636*V(52)+0.1*V(55)&
              &+0.27*V(55)+V(55)+V(55)+0.7*V(55)+0.7*V(55)+0.918*V(69)+0.68*V(55)+0.6*V(69)+0.271*V(68)+0.68*V(55)+0.6*V(69)&
              &+0.68*V(55)+V(69)+0.68*V(55)+V(52)+0.5*V(53)+0.5*V(53)
  FAM(26) = V(53)+0.35*V(53)+0.122*V(53)+0.5*V(53)+0.102*V(53)+0.075*V(53)+0.5*V(53)+0.29*V(53)+0.14*V(53)+0.255*V(53)&
              &+0.375*V(56)+V(53)+0.5*V(58)+0.88*V(53)+0.085*V(53)+0.088*V(53)+0.5*V(53)+0.234*V(53)+0.4*V(53)+0.143*V(53)&
              &+0.5*V(53)+V(53)+0.234*V(53)+0.9*V(53)+0.65*V(53)+0.07*V(53)+0.07*V(53)+0.52*V(53)+0.078*V(55)+V(53)+V(53)&
              &+V(53)+V(53)+V(53)+V(53)+V(53)+V(53)+V(53)+V(53)+V(53)+0.5*V(53)+0.55*V(53)+V(53)+V(53)+0.58*V(53)+0.3*V(53)&
              &+V(53)+V(53)+0.5*V(53)+0.25*V(53)+0.5*V(54)+0.95*V(69)+0.01*V(55)+0.01*V(55)+V(53)+V(69)+V(53)+V(69)+V(53)&
              &+V(69)+0.5*V(53)+0.5*V(53)
  FAM(27) = 0.05*V(68)+0.05*V(54)+0.05*V(68)+0.05*V(69)+V(54)+V(54)+0.3*V(55)+0.3*V(55)+0.082*V(69)+V(54)
  FAM(28) = V(55)+0.85*V(55)+0.5*V(55)+0.78*V(55)+0.79*V(55)+V(55)+V(55)+0.7*V(55)+0.7*V(55)+V(55)+0.68*V(55)+V(55)&
              &+V(55)+0.68*V(55)+0.68*V(55)+0.68*V(55)+V(55)+V(55)+V(55)+V(55)+V(55)+V(55)+V(55)+V(55)
  FAM(29) = V(56)+0.07*V(58)+V(56)+0.25*V(56)+0.64*V(56)
  FAM(30) = 0.25*V(57)+0.15*V(57)+V(57)+V(57)+V(57)+0.07*V(57)+0.5*V(57)+0.5*V(57)+V(57)+V(57)+V(57)
  FAM(31) = V(58)+V(58)+0.32*V(58)+0.86*V(58)+0.93*V(58)+V(58)+0.5*V(58)+0.15*V(58)+0.75*V(58)+0.16*V(58)+0.38*V(58)+0.5&
              &*V(58)+0.5*V(58)+V(58)+2*V(58)+V(58)+0.5*V(58)+V(58)+0.1*V(58)+0.64*V(58)+0.32*V(58)+V(58)+0.75*V(58)+V(58)&
              &+V(58)+V(58)+V(58)+V(58)+V(58)+V(58)+V(58)+V(58)+V(58)+V(58)+V(58)+V(58)+0.32*V(58)
  FAM(32) = V(59)+V(59)
  FAM(33) = V(60)+V(60)
  FAM(34) = V(61)+V(61)
  FAM(35) = V(62)+V(62)
  FAM(36) = V(63)
  FAM(37) = V(64)+V(74)+V(75)+V(64)+V(74)
  FAM(38) = V(65)+V(65)
  FAM(39) = V(66)
  FAM(40) = V(67)
  FAM(41) = 0.28*V(68)+0.49*V(68)+0.95*V(68)+0.224*V(68)+0.49*V(68)+0.95*V(68)+0.459*V(69)+0.459*V(69)+V(68)+V(68)+0.459&
              &*V(69)+V(68)+V(68)+0.5*V(69)+V(68)+V(68)
  FAM(42) = 1.05*V(69)+0.459*V(69)+0.459*V(69)+1.05*V(69)+0.459*V(69)+1.05*V(69)+0.5*V(69)+2.05*V(69)
  FAM(43) = 0.1*V(70)
  FAM(44) = 0.1*V(71)
  FAM(45) = 0.1*V(72)
  FAM(46) = 0.1*V(73)
  FAM(47) = V(74)+V(74)
  FAM(48) = V(75)
  FAM(49) = V(76)
  FAM(50) = V(77)
  FAM(51) = V(78)
  FAM(52) = V(79)
      
END SUBROUTINE ComputeFamilies

! End of ComputeFamilies function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



END MODULE gckpp_Util

